<?php

namespace App\Http\Middleware;
use App\Service\DataReturnService as DRS;
use Illuminate\Support\Facades\Cache;

use Closure;

class CheckLogin
{
    /**
     * Handle an incoming request.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \Closure  $next
     * @return mixed
     */
    public function handle($request, Closure $next)
    {
        $postData = $request->post();
        $token = Cache::get($postData['token']);
        if(empty($token)){
            return DRS::returnErr('false', 401, '未登录或登录已过期，请重新登录。');       
        }
        return $next($request);
    }
}
